<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title><fmt:message code="dem.th.Poag" /></title>
    <link rel="stylesheet" href="/css/officialDocument/officialDocument.css">
    <link rel="stylesheet" type="text/css" href="../lib/pagination/style/pagination.css"/>
    <link rel="stylesheet" type="text/css" href="/css/base/base.css?20201106.1" />
    <link rel="stylesheet" href="/css/notice/noticeManagement.css">
    <link rel="stylesheet" type="text/css" href="../lib/laydate.css"/>
    <link rel="stylesheet" href="/css/workflow/work/automaticNumbering.css">
    <link rel="stylesheet" href="/css/notice/noticeManagement.css">

    <%--<link rel="stylesheet" type="text/css" href="../css/news/new_news.css"/>--%>
    <%--<link rel="stylesheet" type="text/css" href="../css/news/management_query.css" />--%>

    <!-- 门户设置  -->
    <script src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="../js/news/page.js"></script>

    <script src="../lib/laydate/laydate.js"></script>
    <script src="../lib/layer/layer.js?20201106"></script>
    <script src="../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>


    <script src="../../lib/layer/layer.js?20201106"></script>
    <script src="/js/base/tablePage.js"></script>
    <style>
        .total{
            width: 98%;
            margin: auto;
            margin-top: 118px;
        }
        .navigation{
            background: none;

        }
        a {
            text-decoration: none;
            color: #207bd6;
            cursor: pointer;
        }
        select{
            padding: 5px 8px !important;
        }
        td{
            font-size: 11pt;
            line-height: 19px;
            word-break: keep-all;
            white-space: nowrap;
            text-overflow: ellipsis;
            -webkit-box-orient: vertical;
            overflow: hidden;
            text-align: center;
        }
        .query {
            width: 550px;
            margin: 133px auto;
        }
        b{
            color: red;
        }

        .all{
            padding-left: 38px;
            display: none;
        }
        .all li{
            margin: 5px 0;
        }

        .btnsava {
            padding: 5px 15px;
            border-radius: 4px;
            background: #2b7fe0;
            color: #fff;
        }
        .div_IMG{
            margin-left: 15px;
        }
        .div_txt{
            margin-left: 34px;
        }
        .newBtn{
            margin-top:22px;
        }
        #deptChoose{
            width: 150px;
            border-radius: 3px;
            margin-left: 28px;
            border: 1px solid #ddd;
        }
        .inputlayout{
            height:246px;
        }
        #user,#dept{
            width:180px;
            height:75px;
            border-radius: 3px;
            border: 1px solid #ddd;
            margin-left: 28px;
        }
        .inputlayout ul li label{
            width:96px;
        }
    </style>
</head>
<link rel="stylesheet" type="text/css" href="/css/commonTheme/${sessionScope.InterfaceModel}/commonTheme.css"/>
<body>
<div class="head-top">

</div>
<div class="navigation" style="margin-top: 46px;">
    <img src="/img/commonTheme/${sessionScope.InterfaceModel}/daishen.png" alt="">
    <h2>报表权限管理</h2>
    <div style="padding-right:10px;" class="newBtn" id="back">
        <div class="div_txt">返回</div>
    </div>
    <div style="padding-right:10px;" class="newBtn" id="user_btn">
        <div class="div_txt" style="margin-left: 21px;">添加权限</div>
    </div>

</div>

<div class="portal" >
    <form id="queryNews">
        <table class="clearfix total">
            <thead>
            <tr>
                <th>管理员</th>
                <th>权限范围</th>
                <th><fmt:message code="notice.th.operation" /></th>
            </tr>
            </thead>
            <tbody>

            </tbody>
        </table>
    </form>
</div>

<div class="portalTime" style="display: none">
    <div class="query">
        <div class="header"><fmt:message code="vote.th.Sorg" /></div>
        <form id="ajaxform" action="">
            <input type="hidden" name="read">
            <input type="hidden" name="sendTime">
            <table style="width: 100%">
                <tbody>

                <tr class="borderNone" >
                    <%--<td width="30%" class="color"><fmt:message code="notice.th.content"/>：</td>--%>
                    <td width="100%" colspan="2" >
                        <input id="times" style="padding-left: 10px;width: 50%;height: 30px;" type="text" placeholder="<fmt:message code="doc.th.enterTime" />" name="times"> <fmt:message code="system.th.second" />
                    </td>
                </tr>
                <tr class="borderNone">
                    <td colspan="2" style="text-align: center">
                        <a href="javascript:;" class="btnsava" onclick="ajaxtimes()"><fmt:message code="global.lang.ok" /></a>
                        <%--<a href="javascript:;" style="margin-left: 10px" class="btnsava chongtian"  ><fmt:message code="global.lang.refillings"/></a>--%>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
    </div>
</div>


<script>
    var rId = $.GetRequest().rId

    $(function () {
        $.ajax({
            type:'post',
            url:'/reportSettings/queryReportPermission',
            dataType:'json',
            data:{
                rId:rId
            },
            success:function (json) {
                if(json.flag){
                    var v=1;
                    var arr=json.obj;
                    var str=""
                    for(var i=0;i<arr.length;i++){

                        str+='<tr><td>'+ arr[i].userStr +'</td><td>'+function(){
                            if(arr[i].deptStr=='DEPT'){
                                return '本部门'
                            }else if(arr[i].deptStr=='ALLDEPT'){
                                return '全部部门'
                            }else{
                                return arr[i].deptStr
                            }
                            }()+'</td>\
                        <td>'
                            +'<a href="javascript:void (0)" class="newsBtntwo" onclick="stoprwo(' + arr[i].pid + ',' + arr[i].rid + ')"><fmt:message code="global.lang.edit" /></a><a href="javascript:void (0)" onclick="deleteList(' + arr[i].pid + ',' + arr[i].rid + ')">删除</a></td></tr>'
                    }
                    $('#queryNews table tbody').html(str)
                }
            }
        })
    })

//    返回
    $('#back').click(function(){
        self.parent.document.getElementById('iframe').src='/reportSettings/reportSettingsList';
    })





    //新建
    $('#user_btn').on('click',function () {

        layer.open({
            type: 1,
            title:['<fmt:message code="global.lang.new" />', 'background-color:#2b7fe0;color:#fff;'],
            area: ['500px', '350px'],
            shadeClose: true, //点击遮罩关闭
            // btn: ['创建', '取消'],
            content:'<form id="saveRule" class="layui-form"><div class="inputlayout">' +
            '<ul>' +
            '<li class="clearfix">' +
            '<label>部门范围 ：</label><select id="deptChoose"><option value="0">全体部门</option><option value="1">本部门</option><option value="2">指定部门</option></select><input id="hid" value="allDept" type="hidden">' +
            '</li>' +
            '<li class="clearfix deptLi"  style="display:none">' +
            '<label>部门 ：</label>' +
            '<textarea id="dept"></textarea>'+
            '<a style="margin: 0 10px;" class="deptAdd"><fmt:message code="global.lang.add" /></a>'+
            '<a class="deptClear"><fmt:message code="global.lang.empty" /></a>'+
            '</li>' +
            '<li class="clearfix">' +
            '<label>人员 ：</label>' +
            '<textarea id="user"></textarea>'+
            '<a style="margin: 0 10px;" class="userAdd"><fmt:message code="global.lang.add" /></a>'+
            '<a class="userClear"><fmt:message code="global.lang.empty" /></a>'+
            '</li>' +
            '</ul>' +
            '</div></form>',
            btn: ['<fmt:message code="global.lang.save" />','<fmt:message code="depatement.th.quxiao" />'],
            yes: function (index) {
                var dept=""
                if($('#deptChoose').val()=='0'){
                    dept='ALLDEPT'
                }else if($('#deptChoose').val()=='1'){
                    dept='DEPT'
                }else{
                    dept=$('#dept').attr('deptId')
                }
                $.ajax({
                    type:'post',
                    url:'/reportSettings/newReportPermission',
                    dataType:'json',
                    data:{
                        rId:rId,
                        userStr:$('#user').attr('user_id'),
                        deptStr:dept
                    },
                });
                layer.close(index);
                location.reload();
            },
            success:function(res){
                $('#deptChoose').change(function(){
                    if($('#deptChoose').val()=='0'){
                        $('.deptLi').hide();
                    }else if($('#deptChoose').val()=='1'){
                        $('.deptLi').hide();
                    }else{
                        $('.deptLi').show();
                    }
                })
            },

        });

    })

    //编辑

    function stoprwo(pid,rid){
        $.ajax({
            type:'post',
            url:'/reportSettings/selectReportPermission',
            dataType:'json',
            data: {
                id: pid,
                rId:rId
            },
            success:function(res){
                if(res.flag){
                    var data=res.obj[0];
                    layer.open({
                        type: 1,
                        title:['编辑', 'background-color:#2b7fe0;color:#fff;'],
                        area: ['500px', '350px'],
                        shadeClose: true, //点击遮罩关闭
                        // btn: ['创建', '取消'],
                        content:'<form id="saveRule" class="layui-form"><div class="inputlayout">' +
                        '<ul>' +
                        '<li class="clearfix">' +
                        '<label>部门范围 ：</label><select id="deptChoose"><option value="0">全体部门</option><option value="1">本部门</option><option value="2">指定部门</option></select><input id="hid" value="allDept" type="hidden">' +
                        '</li>' +
                        '<li class="clearfix deptLi"  style="display:none">' +
                        '<label>部门 ：</label>' +
                        '<textarea id="dept"></textarea>'+
                        '<a style="margin: 0 10px;" class="deptAdd"><fmt:message code="global.lang.add" /></a>'+
                        '<a class="deptClear"><fmt:message code="global.lang.empty" /></a>'+
                        '</li>' +
                        '<li class="clearfix">' +
                        '<label>人员 ：</label>' +
                        '<textarea id="user"></textarea>'+
                        '<a style="margin: 0 10px;" class="userAdd"><fmt:message code="global.lang.add" /></a>'+
                        '<a class="userClear"><fmt:message code="global.lang.empty" /></a>'+
                        '</li>' +
                        '</ul>' +
                        '</div></form>',
                        btn: ['<fmt:message code="global.lang.save" />','<fmt:message code="depatement.th.quxiao" />'],
                        success:function(res){
                            if(data.deptStr == 'ALLDEPT'){
                                $('#deptChoose').val('0')
                                $('.deptLi').hide();
                            }else if(data.deptStr == 'DEPT'){
                                $('#deptChoose').val('1')
                                $('.deptLi').hide();
                            }else{
                                $('#deptChoose').val('2')
                                $('.deptLi').show();
                                var dept="";
                                var deptId="";
                                if(data.deptStr!=""&&data.deptStr.indexOf(',')>-1){
                                    var arr = data.deptStr.split(',');
                                    for(var i=0;i<arr.length;i++){
                                        dept += arr[i].split(':')[1]+',';
                                        deptId += arr[i].split(':')[0]+',';
                                    }
                                }else  if(data.deptStr!=""&&data.deptStr.indexOf(',')<=-1){
                                    var arr = data.deptStr;
                                    dept = arr.split(':')[1]+',';
                                    deptId = arr.split(':')[0]+',';
                                }else{
                                    dept="";
                                    deptId="";
                                }
                                $('#dept').val(dept);
                                $('#dept').attr('deptId',deptId)

                            }
                            var user="";
                            var userId="";
                            if(data.userStr!=""&&data.userStr.indexOf(',')>-1){
                                var arr = data.userStr.split(',');
                                for(var i=0;i<arr.length;i++){
                                    user += arr[i].split(':')[1]+',';
                                    userId += arr[i].split(':')[0]+',';
                                }
                            }else  if(data.userStr!=""&&data.userStr.indexOf(',')<=-1){
                                var arr = data.userStr;
                                    user = arr.split(':')[1]+',';
                                    userId = arr.split(':')[0]+',';
                            }else{
                                 user="";
                                 userId="";
                            }

                            $('#user').val(user);
                            $('#user').attr('user_id',userId)


                            $('#deptChoose').change(function(){
                                if($('#deptChoose').val()=='0'){
                                    $('.deptLi').hide();
                                }else if($('#deptChoose').val()=='1'){
                                    $('.deptLi').hide();
                                }else{
                                    $('.deptLi').show();
                                }
                            })
                        },
                        yes: function (index) {
                            var dept=""
                            if($('#deptChoose').val()=='0'){
                                dept='ALLDEPT'
                            }else if($('#deptChoose').val()=='1'){
                                dept='DEPT'
                            }else{
                                dept=$('#dept').attr('deptId')
                            }
                            $.ajax({
                                type:'post',
                                url:'/reportSettings/updateReportPermission',
                                dataType:'json',
                                data:{
                                    rId:rId,
                                    pId:pid,
                                    userStr:$('#user').attr('user_id'),
                                    deptStr:dept
                                },
                            });
                            layer.close(index);
                            location.reload();
                        },

                    });
                }

            }

        });
    }

    function checkehuo(name, val) {
        if (val == '') {
            return;
        }
        $('[name="' + name + '"]').find('option').each(function(i, n) {
            if ($(this).val() == val) {
                $(this).attr('selected', 'selected')
            } else {
                $(this).removeAttr('selected', 'selected')
            }
        })
    }
    // 获取角色信息控件
    $(document).on("click",".userPrivAdd",function(){
        priv_id="accessPrivPriv";
        $.popWindow("../common/selectPriv");
    });
    // 清空角色信息
    $(document).on('click','.userPrivClear',function () {
        $('#accessPrivPriv').attr("privid","");
        $('#accessPrivPriv').attr("userpriv","");
        $('#accessPrivPriv').val("");
    });

    // 获取部门信息控件
    $(document).on("click",".deptAdd",function(){
        dept_id="dept";
        $.popWindow("../common/selectDept");
    });
    // 清空部门信息
    $(document).on('click','.deptClear',function () {
        $('#accessPrivDept').attr("deptid","");
        $('#accessPrivDept').attr("deptno","");
        $('#accessPrivDept').val("");
    });

    //选人控件
    $(document).on("click",".userAdd",function(){
        user_id='user';
        $.popWindow("../common/selectUser");

    });
    // 清空用户信息
    $(document).on('click','.userClear',function () {
        $('#user').attr("username","");
        $('#user').attr("user_id","");
        $('#user').attr("dataid","");
        $('#user').attr("userprivname","");
        $('#user').val("");
    });

    function deleteList(pid,rid) {

        layer.confirm('<fmt:message code="attend.th.qued" />？', {
            btn: ['<fmt:message code="global.lang.ok" />', '<fmt:message code="depatement.th.quxiao" />'], //按钮
            title: "<fmt:message code="event.th.DeleteInformation" />"
        }, function() {
            //确定删除，调接口
            $.ajax({
                type: 'post',
                url: '/reportSettings/deleteReportPermission',
                dataType: 'json',
                data: {
                    rid:rId,
                    id:pid,
                },
                success: function(res) {
                    if (res.flag) {
                        $.layerMsg({ content: '<fmt:message code="workflow.th.delsucess" />！', icon: 1 });
                    } else {
                        $.layerMsg({ content: '<fmt:message code="lang.th.deleSucess" />！', icon: 1 });
                    }
                    location.reload();
                }
            })
        }, function() {

            layer.closeAll();
        });

    }

    // 时间


    var text3 = document.getElementById("times");
    text3.onkeyup = function(){
        this.value=this.value.replace(/\D/g,'');
    }

    function ajaxtimes() {
        var tm = $('#times').val()
        $.ajax({
            type:'post',
            url:'/syspara/updateSysParaByParaName',
            dataType:'json',
            data: {
                paraName:'PORTALS_TIME',
                paraValue: tm
            },
            success:function(res){
                if(res.flag){
                    $.layerMsg({content:'<fmt:message code="depatement.th.Modifysuccessfully" />',icon:1})
                }
            }
        })
    }


</script>

</body>
</html>
